package SwordFingerOffer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Q06_ReversePrintLink {

    //递归
    public int[] reversePrint(ListNode head) {
        if (head == null){
            return null;
        }
        List<Integer> ans = new ArrayList<>();
        process(head,ans);
        int[] res = new int[ans.size()];
        for (int i = 0; i < res.length; i++) {
            res[i] = ans.get(i);
        }
        return res;
    }

    public void process(ListNode head, List<Integer> list){
        //到达尾节点
        if (head.next == null){
            list.add(head.val);
            return;
        }
        //没有到达尾节点
        process(head.next, list);
        list.add(head.val);
    }
}
